:inoremap <silent> <S-ENTER> <c-r>=SkipPair()<CR>
:inoremap <silent> <S-SPACE> <ESC>la
:inoremap <silent> ( ()<ESC>i
:inoremap <silent> ) <c-r>=ClosePair(')')<CR>
:inoremap <silent> { <c-r>=CloseBrace()<CR>
:inoremap <silent> } <c-r>=ClosePair('}')<CR>
:inoremap <silent> [ []<ESC>i
:inoremap <silent> ] <c-r>=ClosePair(']')<CR>
:inoremap <silent> ;; <ESC>A;<CR>

function! ClosePair(char) 
        if getline('.')[col('.') - 1] == a:char 
                return "\<Right>"
        else 
                return a:char
        endif 
endf 
function! Semicolon() 
        "echo getline('.')[col('.')] 
        if getline('.')[col('.')] == ')'
                return "<ESC>A;"
        elseif getline('.')[col('.')] == '}'
                return "\<ESC>A;"
        elseif getline('.')[col('.')] == ']'
                return "\<ESC>A;"
        else 
                return ";"
        endif 
endf 
function! SkipPair() 
        if getline('.')[col('.') - 1] == ')'
                return "\<ESC>o"
        else 
                normal j
                let curline = line('.')
                let nxtline = curline
                while curline == nxtline
                        if getline('.')[col('.') - 1] == '}'
                                normal j
                                let nxtline = nxtline + 1
                                let curline = line('.')
                                continue 
                        else 
                                return "\<ESC>i"
                        endif 


                endwhile 
                return "\<ESC>o"
        endif 
endf 
function! CloseBrace() 
        if getline('.')[col('.') - 2] == '='
                return "{}\<ESC>i"
        elseif getline('.')[col('.') - 3] == '='
                return "{}\<ESC>i"
        elseif getline('.')[col('.') - 1] == '{'
                return "{}\<ESC>i"
        elseif getline('.')[col('.') - 2] == '{' 
                return "{}\<ESC>i"
        elseif getline('.')[col('.') - 2] == ',' 
                return "{}\<ESC>i"
        elseif getline('.')[col('.') - 3] == ',' 
                return "{}\<ESC>i"
        else 
                return "{\<ENTER>}\<ESC>O"
        endif 
endf 



